﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using fcwms.Common;

public partial class admin_user_role_list : SessionManage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ChkAdminLevel("sys_role", ActionEnum.View.ToString()); //检查权限
            fcwms.Model.dt_users model = GetAdminInfo();
            RptBind("role_type>=" + model.role_type);
        }
    }

    #region 数据绑定==============================
    public void RptBind(string _strWhere)
    {
        //fcwms.BLL.dt_role bll = new fcwms.BLL.dt_role();
        //fcwms.Model.dt_users model = GetAdminInfo();
      
        //StringBuilder strSql = new StringBuilder();
        //strSql.Append("select * from dt_role where role_type >= @role_type");
        //SqlParameter[] parms = new SqlParameter[] { 
        //new SqlParameter("@role_type",model.role_type)};

        //DataSet ds = DbHelperSQL.Query(strSql.ToString(),parms);
        //rptList.DataSource = ds.Tables[0];
        //rptList.DataBind();

        fcwms.BLL.dt_role bll = new fcwms.BLL.dt_role();
        this.rptList.DataSource = bll.GetList(_strWhere);
        this.rptList.DataBind();

        //this.AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;  //DataView的Count属性,AspNetPager的RecordCount属性.
        //PagedDataSource pds = new PagedDataSource();
        //pds.AllowPaging = true;                                   //启用分页.
        //pds.PageSize = AspNetPager1.PageSize;                     //每页要显示的记录条数.      
        //pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1; //当前页索引.
        //pds.DataSource = ds.Tables[0].DefaultView;                //分页数据源以DataView为数据源.     
        //rptList.DataSource = pds;
        //rptList.DataBind();
    }
    #endregion

    #region 返回角色类型名称======================
    protected string GetTypeName(int role_type)
    {
        string str = "";
        switch (role_type)
        {
            case 1:
                str = "超级用户";
                break;
            default:
                str = "系统用户";
                break;
        }
        return str;
    }
    #endregion
 
    #region 删除操作==============================
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        ChkAdminLevel("sys_role", ActionEnum.Delete.ToString()); //检查权限
        fcwms.BLL.dt_role bll = new fcwms.BLL.dt_role();
        for (int i = 0; i < rptList.Items.Count; i++)
        {
            int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
            CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
            if (cb.Checked)
            {
                string role_name = bll.GetTitle(id);
                if (role_name == "超级管理员")
                {
                    MessageBox.Jscript(this, "不能删除该角色名称！", "role_list.aspx", "Error");
                    return;
                }
                bll.Delete(id);
            }
        }
        MessageBox.Jscript(this, "批量删除成功啦", "role_list.aspx", "Success");
    }   
    #endregion

}